<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title></title>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.5/lib/index.css">
		<link rel="stylesheet" href="/statics/wxdemo/css/login.css">
		<script src="/statics/wxdemo/js/flexble.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@2.5/lib/vant.min.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/sdk/webimSDK3.1.2.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/js/WebIMConfig.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/js/webconn.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/js/localstorage.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/utils/msgtype.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/utils/login.js"></script>
	</head>
	<body>
		<div class="bigbox" id="bigbox">
			<div class="innerbox">
				<!-- <div class="login" @click="clearloc">获取历史</div> -->
				<div class="loginbox" v-if="islogin">
					<div class="inpbox">
						用户名：<input type="text" v-model="name">
					</div>
					<div class="inpbox">
						密&nbsp;&nbsp;&nbsp;&nbsp;码：<input type="password" v-model="passw">
					</div>
					<div class="login" @click="login">登录</div>
					<div class="go" @click="islogin = false">去注册></div>
				</div>
				<div class="loginbox" v-else>
					<div class="inpbox">
						用户名：<input type="text" v-model="rename">
					</div>
					<div class="inpbox">
						密&nbsp;&nbsp;&nbsp;&nbsp;码：<input type="password" v-model="repassw">
					</div>
					<div class="login" @click="register">注册</div>
					<div class="go" @click="islogin = true">去登录></div>
				</div>
			</div>
		</div>
	</body>
</html>
<script type="text/javascript">
WebIM.message = WebIM.default.message;
//jgqpc1   123456
//jgqpc2   123456 
//jgqpc3   123456 
var webvue = new Vue({
	el: '#bigbox',
	data() {
		return {
			name:'',
			passw:'',
			rename:'',
			repassw:'',
			islogin:true,
			value:'',
			sendID: ''
		}
	},
	methods:{
		send(){
			// console.log(conn.subscribe)
			var that = this;
			console.log(that.value);
			    // WebIM.conn.subscribe({
			    //     to: that.value,
			    //     message: '加个好友呗!'   
			    // });
			// return
			
		},
		login(){
			// window.location.href = '/Welcome/chatlist'
			// return
			if(!this.name){
				vant.Toast('请输入用户名')
				// this.$message.error('请输入用户名');
				return
			}
			if(!this.passw){
				vant.Toast('请输入密码')
				// this.$message.error('请输入密码');
				return 
			}
			isfirst = 0;
			login(this.name,this.passw)
			saveStorage('myid',this.name)
			// saveStorage('mypass',this.passw)
			 
		},
		register(){
			var that = this;
			if(!this.rename){
				vant.Toast('请输入用户名')
				// this.$message.error('请输入用户名');
				return
			}
			if(!this.repassw){
				vant.Toast('请输入密码')
				// this.$message.error('请输入密码');
				return
			}
			var options = { 
			    username: this.rename,
			    password: this.repassw,
			    appKey: WebIM.config.appkey,
			    success: function (res) {
					console.log('注册成功！',res)
					vant.Toast.success('注册成功')
				 },  
			    error: function (e) { 
					vant.Toast.fail('注册成功')
				}, 
			    apiUrl: WebIM.config.apiURL
			  }; 
			  conn.registerUser(options);
		},
		clearloc(){
			console.log('拉取')
			WebIM.conn.fetchHistoryMessages({
			    queue: "jgqpc2",
			    isGroup: false,
			    count: 5,
			    success: function(){
					console.log('拉取成功',res)
				},
			    fail: function(res){
					console.log('报错',res)
				}
			})
		}
	}
})
// function hasGetUserMedia() {
//   // Note: Opera builds are unprefixed.
//   return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
//             navigator.mozGetUserMedia || navigator.msGetUserMedia);
// }

// if (hasGetUserMedia()) {
//   // Good to go!
//   alert('yes!');
// } else {
//   alert('getUserMedia() is not supported in your browser');
// }
</script>